/**
 * @param {number[]} nums
 * @return {number[][]}
 * 输入：nums = [1,2,3]
输出：[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]
 */
var subsets = function (nums) {
  const res = [[]]
  const sub = (curr, nums) => {
    // if (curr.length === nums.length) {
    //   return
    // }
    if (nums.length === 0) {
      return
    }
    let i = 0
    const currNums = [...nums]
    while (i < nums.length) {
      const currNum = [...curr]
      const delArr = currNums.splice(0, 1)
      currNum.push(delArr[0])
      res.push(currNum)
      sub(currNum, currNums)
      i++
    }
  }
  sub([], [...nums])
  return res
}
console.log(subsets([1, 2, 3]))
